package cn.edu.hrbcu.es.invigilatemanagerment.service;

import cn.edu.hrbcu.es.invigilatemanagerment.dao.ClazzMapper;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.Clazz;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.ClazzExample;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClazzServiceImpl implements IClazzService{
    @Autowired
    private ClazzMapper clazzMapper;
    @Override
    public int insertClazz(Clazz clazz) {
        return clazzMapper.insert(clazz);
    }

    @Override
    public List<Clazz> queryAllClazz() {
        return clazzMapper.selectAll();
    }

    @Override
    public Clazz queryClazzById(Integer id) {
        return clazzMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteClazzById(Integer id) {
        return clazzMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateClazzById(Clazz clazz) {
        return clazzMapper.updateByPrimaryKey(clazz);
    }

    @Override
    public List<Clazz> queryClazzByName(String name) {
        ClazzExample example = new ClazzExample();
        ClazzExample.Criteria criteria = example.createCriteria();
        criteria.andNameEqualTo(name);
        return clazzMapper.selectByExample(example);
    }

    @Override
    public List<Clazz> queryClazzByPage(int pageNow, int pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<Clazz> clazzes = clazzMapper.selectAll();
        PageInfo<Clazz> clazzPageInfo = new PageInfo<>(clazzes);
        return clazzPageInfo.getList();
    }

    @Override
    public int queryTotalCount() {
        ClazzExample example = new ClazzExample();
        ClazzExample.Criteria criteria = example.createCriteria();
        criteria.getAllCriteria();
        return (int) clazzMapper.countByExample(example);
    }
//    ClazzExample example = new ClazzExample();
//    ClazzExample.Criteria criteria = example.createCriteria();
//        criteria.getAllCriteria();
}
